<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://unpkg.com/vue"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" />
  <style>
    .container {
      position: absolute;
      width: 200px;
      height: 100px;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }
  </style>
</head>

<body>
  <div id="root"></div>
  <script>
    /* 
      1. css属性设置不使用css动画、过渡
      2. 通过实现钩子函数实现动画
      @before-enter
      @enter
      @after-enter
      @befo re-leave
      @leave
      @after-leave
      3. js动画效果不如css动画
    */
    const app = Vue.createApp({
      template: `
      <div class="container">
        <transition 
        :css="false" 
        @before-enter="beforeEnterHandle"
        @enter="enterHandle"
        @after-enter="afterEnterHandle"
        >
          <div v-if="isShow">Hello World1</div>
        </transition>
        <button @click="isShow = !isShow">切换</button>
      </div>
    `,
      data() {
        return {
          isShow: false
        }
      },
      methods: {
        beforeEnterHandle(el) {
          el.style.color = 'skyblue'
        },
        enterHandle(el, done) {
          const animation = setInterval(() => {
            const color = el.style.color;
            if (color === 'red') {
              el.style.color = 'green'
            } else {
              el.style.color = 'red'
            }
          }, 1000)
          setTimeout(() => {
            clearInterval(animation)
            done()
          }, 3000);
        },
        afterEnterHandle(){
          alert('动画结束');
        }
      }
    })
    const vm = app.mount('#root');

  </script>
</body>

</html>